#include <stdio.h>
#include <stdlib.h>

#define true 1
#define false 0
typedef unsigned char bool;
#define MaxSize 10
typedef struct{
    int data[MaxSize];
    int length;
}SqList;

void InitList(SqList *L){
    for(int i=0; i<MaxSize; i++){
        L->data[i] = 0; //将所有数据元素设置为默认值
    }
    L->length = 0;      //顺序表初始长度为0
}

bool ListDelete(SqList *L,int num,int *e){//e会将删除的元素值带回来

    if(num<1||num>L->length+1){         //判断位序范围是否超过
        printf("parameter num error,num<1 or num>L->length+1\n");
        return false;
    }
    if(L->length == 0){                 //判空
        printf("List is empty,can't delete.\n");
        return false;
    }
    *e = L->data[num-1];                //将删除的值带回

    printf("i\t\ti-1\n");

    for(int i=num; i<L->length;i++){
        L->data[i-1] = L->data[i];      //将后面的值往前移动一个位置,比如将data[3]的位置数据移动到data[2]
        L->data[i] = 520;
        printf("%d\t->\t%d\n",i-1,i);
    }

    L->length--;
    
    return true;
}

int main(){
    SqList L;
    int e = -1;
    InitList(&L);

    printf("insert some values:111 data[0]~data[5]\n");
    for (int i = 0;i<=5;i++){
        L.data[i] = i*111;
    }
    L.length = 6;

    for (int i = 0;i<=L.length-1;i++){
        printf("data[%d] = %d\n",i,L.data[i]);
    }

    ListDelete(&L, 3, &e);  //调用delete函数将位序为3的数据删除
    printf("e = %d\n",e);         //显示删除的值e

    for (int i = 0;i<=L.length-1;i++){
        printf("data[%d] = %d\n",i,L.data[i]);
    }
    return 0;
}
